package br.com.obardavez.resources;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import br.com.obardavez.entity.Promocao;
import br.com.obardavez.service.PromocaoService;

import com.google.inject.Inject;

@Path("/promocao")
public class PromocaoResource {

	@Inject
	private PromocaoService promocaoService;
	
	@POST
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	public Response save(Promocao promocao) {
		try{
			promocaoService.saveOrUpdate(promocao);
			return Response.ok("Salvo com sucesso").build();
		}catch (Exception e) {
			e.printStackTrace();
			return Response.status(Status.INTERNAL_SERVER_ERROR).build();
		}
    }

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<Promocao> getItensModerados(){
		
		return promocaoService.getItensModerados();
	}
	
	
}
